package com.wanghlme.day27.web;

import com.wanghlme.day27.service.ICompanyService;
import com.wanghlme.day27.service.impl.CompanyServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/updateEmpStatus")
public class UpdateEmpStatusAction extends HttpServlet {
    private ICompanyService companyService;

    public UpdateEmpStatusAction() {
        companyService = new CompanyServiceImpl();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        String status = req.getParameter("status");
        int result = companyService.updateEmpStatus(Integer.parseInt(id), Integer.parseInt(status));
        PrintWriter out = resp.getWriter();
        out.print(result == 1 ? "1" : "0");
        out.flush();
        out.close();
    }
}
